Skip to content

Fix mismatch of enum sizes between WASM and host#4676

Merged
lum1n0us merged 1 commit intobytecodealliance:mainfrom
project-ocre:fix/socket_enum_sizes
Mar 9, 2026
Merged

Fix mismatch of enum sizes between WASM and host#4676
lum1n0us merged 1 commit intobytecodealliance:mainfrom
project-ocre:fix/socket_enum_sizes

Conversation

@dkouba-atym
Copy link
Contributor

While working with WAMR on Zephyr, I discovered that the sizes of a couple socket enums were not consistent between the host and inside of WASM. This resulted in an inability to create a UDP socket, as the layout of the enum was compressed (enums became 1 byte instead of 4) and the offset of hints_enabled was incorrect, and therefore all sockets created were TCP.

In WASM: sizes: enum=4, hints_t=12, off(type)=0 off(family)=4 off(en)=8
In Zephyr host: sizes: enum=1, hints_t=3, off(type)=0 off(family)=1 off(en)=2

As a result I've enforced the struct sizes using the same method it was done for a different enum and added the appropriate assertions to validate.

@lum1n0us
Copy link
Contributor

I believe we should synchronize this modification with core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h.

@lum1n0us lum1n0us added the bug-fix Determine if this PR addresses a bug. It will be used by scripts to classify PRs. label Oct 28, 2025
@kr-t
Copy link
Contributor

kr-t commented Feb 17, 2026

I have replaced enums to defines. Please let me know if you'd like to change some naming or anything else additionally in this PR.

- refactor(wasi_types): deprecate enums in platform_wasi_types.h.
- Use macros instead.

Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com>
Signed-off-by: Dan Kouba <dan@atym.io>
@kr-t kr-t force-pushed the fix/socket_enum_sizes branch from 3c567b8 to ffd4183 Compare February 19, 2026 15:01
@kr-t
Copy link
Contributor

kr-t commented Feb 19, 2026

Squashed and rebased to latest main.

@lum1n0us lum1n0us merged commit d9091cc into bytecodealliance:main Mar 9, 2026
504 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix Determine if this PR addresses a bug. It will be used by scripts to classify PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants